begintownscript;

variables;
short bmessage,pcs,seated,leadchar,rctx,rcty;
string custom_m;

body;

beginstate INIT_STATE;

	set_name(6,"Mayor Candice");
	set_char_dialogue_pic(6,1951,0);
	set_name(25,"Albert");
	set_char_dialogue_pic(25,1960,0);
	set_name(31,"Hoppston");
	set_char_dialogue_pic(31,1945,0);
	set_name(32,"Jewel");
	set_char_dialogue_pic(32,1908,0);
	set_name(48,"Marie");
	set_char_dialogue_pic(48,1950,0);
	set_name(54,"Captain Rupert");
	set_char_dialogue_pic(54,1956,0);

	if(get_flag(28,0) == 1){
		set_terrain(4,21,0);
		set_terrain(4,27,0);
		set_terrain(3,21,0);
		set_terrain(3,27,0);
		set_floor(9,24,109);
		set_floor(10,24,109);
		set_terrain(4,24,226);
	}
	if(get_flag(31,0) >= 3){
		erase_char(31);
		set_terrain(4,24,409);
	}
	if(get_flag(28,0) == 0){
		pcs = 0;
		seated = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE){
				set_character_facing(pcs,6);
				if(seated == 0)
					relocate_character(pcs,5,25);
				if(seated == 1)
					relocate_character(pcs,5,23);
				if(seated == 2)
					relocate_character(pcs,6,25);
				if(seated == 3)
					relocate_character(pcs,6,23);
				seated = (seated + 1);
			}

			pcs = (pcs + 1);
		}
		force_view_center(5,25);
		force_instant_terrain_redraw();
		pause(4);

		set_terrain(4,21,0);
		set_terrain(4,27,0);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);

		set_terrain(3,21,0);
		set_terrain(3,27,0);
		force_instant_terrain_redraw();
		play_sound(79);
		pause(2);

		set_floor(9,24,109);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);

		set_floor(10,24,109);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);

		set_terrain(4,24,226);
		relocate_character(31,5,24);
		set_character_facing(31,6);
		force_instant_terrain_redraw();
		pause(4);

		reset_dialog();
		add_dialog_str(0,"_Well.  Thanks.  That was an unusually large raiding group; you should tell the mayor about it.  And if you want to help us fight the brigands, it'd be appreciated._",0);
		if(party_size() == 1)
			add_dialog_choice(0,"Right, I'll see you later.");
		if(party_size() > 1)
			add_dialog_choice(0,"Right, we'll see you later.");
		bmessage = run_dialog(1);

		set_flag(28,0,1);

		relocate_character(31,8,37);
		force_instant_terrain_redraw();
	}

	if(get_flag(23,0) >= 1){
		erase_char(7);
		erase_char(8);
		erase_char(9);
		erase_char(31);
		erase_char(40);
		erase_char(41);

		rctx = 2;
		while(rctx <= 8){
			rcty = 21;
			while(rcty <= 27){
				set_floor(rctx,rcty,57);
				set_terrain(rctx,rcty,0);

				rcty = (rcty + 1);
			}
			rctx = (rctx + 1);
		}
	}
	else{
		set_floor(9,24,109);
		set_floor(10,24,109);
	}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	leadchar = 0;
	while(char_ok(leadchar) == FALSE){
		leadchar = (leadchar + 1);
	}
	set_flag(29,0,1);
	if(char_loc_x(leadchar) > 17)
		set_flag(29,0,0);
	if(char_loc_x(leadchar) < 11)
		set_flag(29,0,0);
	if(char_loc_y(leadchar) > 31)
		set_flag(29,0,0);
	if(char_loc_y(leadchar) < 27)
		set_flag(29,0,0);
	if((char_loc_x(leadchar) == 12) && (char_loc_y(leadchar) == 27))
		set_flag(29,0,0);

break;

beginstate 10;

	if((get_flag(30,0) > 1) && (get_flag(30,0) < 2)){
		if(party_size() == 1)
			message_dialog("No...  My conversation with the mayor isn't over yet.","");
		if(party_size() > 1)
			message_dialog("No...  My conversation with the mayor isn't over yet.","");
		block_entry(1);
	}

break;

beginstate 11;

	if(get_flag(32,0) == 0){
		if(party_size() == 1)
			message_dialog("The guards lower their polearms, obstructing my path.  _Sorry, adventurer, but you need permission to enter here._","");
		if(party_size() > 1)
			message_dialog("The guards lower their polearms, obstructing our path.  _Sorry, adventurers, but you need permission to enter here._","");
		if(get_flag(30,0) >= 2){
			if(party_size() == 1)
				message_dialog("Fortunately, I'm able to explain to the guards that I received permission from Mayor Candice.  The guards are suspicious, but when I show them the steel key, they ease up a little and let me pass.","");
			if(party_size() > 1)
				message_dialog("Fortunately, we're able to explain to the guards that we received permission from Mayor Candice.  The guards are suspicious, but when we show them the steel key, they ease up a little and let us pass.","");
			set_flag(32,0,1);
		}
		else{
			block_entry(1);
		}
	}

break;

beginstate 12;

	if(get_flag(36,0) == 0){
		if(party_size() == 1)
			message_dialog("These fishing boats have had chairs placed on them, allowing archers to sit on the boats and look out onto the water for brigand activity.","Since, as I know from experience, the brigands aren't just capable of attacking by land.");
		if(party_size() > 1)
			message_dialog("These fishing boats have had chairs placed on them, allowing archers to sit on the boats and look out onto the water for brigand activity.","Since, as we know from experience, the brigands aren't just capable of attacking by land.");
		set_flag(36,0,1);
	}

break;

beginstate 13;

	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}
	move_to_new_town(6,5,5);

break;

beginstate 14;

	if(get_flag(23,0) == 0){
		if(party_size() == 1)
			message_dialog("The guard here lowers his halberd at me, blocking my path up to the ramparts with a large, pointed implement.","_Sorry, pal.  I can't let you up here.  There's a large army out there, and we're under strict orders to let nobody get at 'em.  That includes you._");
		if(party_size() > 1)
			message_dialog("The guard here lowers his halberd at us, blocking our path up to the ramparts with a large, pointed implement.","_Sorry, folks.  I can't let you up here.  There's a large army out there, and we're under strict orders to let nobody get at 'em.  That includes you._");
		block_entry(1);
	}

break;

beginstate 15;

	if(get_flag(23,0) == 0){
		if(party_size() == 1)
			message_dialog("The guards here lowers their halberds at me, blocking the way out of the city.","_This city is under lockdown.  There is a large brigand army outside, and it is not your place to assault it without Captain Rupert's orders._");
		if(party_size() > 1)
			message_dialog("The guards here lowers their halberds at us, blocking the way out of the city.","_This city is under lockdown.  There is a large brigand army outside, and it is not your place to assault it without Captain Rupert's orders._");
		block_entry(1);
	}

break;

beginstate 16;

	if(get_flag(31,0) >= 3){
		if(is_combat() == TRUE)
			end();
		set_flag(34,0,6);

		pcs = 0;
		seated = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE){
				set_character_facing(pcs,6);
				if(seated == 0)
					relocate_character(pcs,5,25);
				if(seated == 1)
					relocate_character(pcs,5,23);
				if(seated == 2)
					relocate_character(pcs,6,25);
				if(seated == 3)
					relocate_character(pcs,6,23);
				seated = (seated + 1);
			}

			pcs = (pcs + 1);
		}
		force_view_center(5,25);
		force_instant_terrain_redraw();
		pause(4);

		set_floor(10,24,59);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);

		set_floor(9,24,57);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);

		set_terrain(3,21,468);
		set_terrain(3,27,468);
		force_instant_terrain_redraw();
		play_sound(79);
		pause(2);

		set_terrain(4,21,337);
		set_terrain(4,27,337);
		force_instant_terrain_redraw();
		play_sound(99);
		pause(2);

		message_dialog("_Here we go!_","The Ten Slayer starts up again and begins leaving port.");

		rctx = 6;
		while(rctx <= 28){
			force_view_center(rctx,25);
			force_instant_terrain_redraw();
			pause(1);

			rctx = (rctx + 1);
		}

		reset_dialog();
		if(party_size() == 1)
			add_dialog_str(0,"The ride this time is a lot more peaceful.  Hoppston seems as surprised as I am.",0);
		if(party_size() > 1)
			add_dialog_str(0,"The ride this time is a lot more peaceful.  Hoppston seems as surprised as we are.",0);
		add_dialog_str(1,"_This is odd...  We're sailing right into their territory, and yet none of their boats are around.  I don't get it.  Well...  Maybe they're afraid?  Yeah-- from when we came by here last, and lost them a patrol._",0);
		add_dialog_str(2,"_..._",0);
		add_dialog_str(3,"_Or...  maybe I should stop looking a gift horse in the mouth and just go._",0);
		add_dialog_str(4,"Soon, Sunset Creek disappears behind a set of crags.  Another gap thereafter quickly reveals a stretch of farmland and forests.  There is a small dock at this gap which Hoppston begins sailing towards.",0);
		add_dialog_str(5,"_This dock isn't in use yet.  Construction is sparse, so you should be able to slip into their territory unnoticed.  Now, good luck-- and don't die!_",0);
		add_dialog_choice(0,"Thanks, you too.");
		bmessage = run_dialog(1);

		move_to_new_town(9,10,10);
	}

break;

beginstate 30;

	if(party_size() == 1)
		message_dialog("This is where Sunset Creek keeps all of its food, since it's a chilled room.  It's also where the guards particularly don't want me to be digging around.","I should be able to survive without looting this besieged town's food stores.  Plus, if I do take their food, odds are I won't survive for long anyway.");
	if(party_size() > 1)
		message_dialog("This is where Sunset Creek keeps all of its food, since it's a chilled room.  It's also where the guards particularly don't want us to be digging around.","We should be able to survive without looting this besieged town's food stores.  Plus, if we do take their food, odds are we won't survive for long anyway.");

break;

